<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>管理员后台首页</title>
		<meta name="renderer" content="webkit">
  		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  		<!-- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> -->
		<link rel="stylesheet" type="text/css" href="<?php echo STATIC_SERVER; ?>/layui/css/layui.css">
		<link rel="stylesheet" type="text/css" href="<?php echo STATIC_SERVER; ?>/<?php echo $common_info['module']; ?>/css/style.css"/>
		<script src="<?php echo STATIC_SERVER; ?>/<?php echo $common_info['module']; ?>/js/jquery-1.12.1.min.js"></script>
	</head>
	<body>
		<div class="xinsu-top">
			<div class="xinsu-top-title">
				<a href="javascript:;">后台管理系统</a>
			</div>
			<div class="xinsu-top-info">
				<?php if ($_SESSION['admin']['role_id']!=2) { ?>
				<div>管理员：<?php echo $_SESSION['admin']['username']; ?></div>
				<div>消息：<a href="/<?php echo $common_info['module']; ?>/message/money"><span id="xinsu-message">0</span></a></div>
				<?php } else { ?>
				<div>用户：<?php echo $_SESSION['admin']['username']; ?>(开户账户)</div>
				<?php } ?>
			</div>
			<div class="xinsu-top-operate">
				<ul>
				<?php if ($_SESSION['admin']['role_id']!=2) { ?>
					<li><a class="xinsu-icon-sort xinsu-icon-geduan" href="/<?php echo $common_info['module']; ?>/stock/gain">盈亏排序</a></li>
				<?php } ?>
					<li><a class="xinsu-icon-renewal xinsu-icon-geduan" href="javascript:clear_system_cache()">更新缓存</a></li>
					<li><a class="xinsu-icon-exit" href="javascript:logout()">注销登录 <?php echo $runtime; ?>ms</a></li>
				</ul>
			</div>
			<div class="xinsu-clear"></div>
		</div>
		<div class="xinsu-left">
			<div class="xinsu-nav">
				<div class="xinsu-nav-time">
					<span id="xinsu-system-date"><?php echo $common_info['week']; ?></span>
					<span id="xinsu-system-time"><?php echo $common_info['time']; ?></span>
				</div>
				<ul class="layui-nav layui-nav-tree" lay-filter="xinsu-nav">
					
					<li class="layui-nav-item xinsu-nav-item-icon1 <?php if ($common_info['current'] == '1') { ?>layui-nav-itemed<?php } ?>"><a href="<?php if ($_SESSION['admin']['role_id']!=2) { ?>/<?php echo $common_info['module'];  } else { ?>/<?php echo $common_info['module']; ?>/user<?php } ?>">系统首页</a></li>
					<li class="layui-nav-item xinsu-nav-item-icon2 <?php if ($common_info['current'] == '2') { ?>layui-nav-itemed<?php } ?>">
						<a href="javascript:;">用户管理</a>
						<dl class="layui-nav-child">
						<?php if ($_SESSION["admin"]['role_id']!=2) { ?>
							<dd <?php if ($common_info['current2'] == '1' && $common_info['current'] == '2') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/ratio">保证金率</a></dd>
						<?php } ?>
							<dd <?php if ($common_info['current2'] == '2' && $common_info['current'] == '2') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/user">会员管理</a></dd>
							<dd <?php if ($common_info['current2'] == '3' && $common_info['current'] == '2') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/staff">员工管理</a></dd>
						<?php if ($_SESSION["admin"]['role_id']!=2) { ?>	
							<dd <?php if ($common_info['current2'] == '4' && $common_info['current'] == '2') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/agent">代理管理</a></dd>
							<dd <?php if ($common_info['current2'] == '5' && $common_info['current'] == '2') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/adm">管理员</a></dd>
						<?php } ?>
						</dl>
					</li>
					
					<!----- Menus only for admin------>
					<?php if ($_SESSION["admin"]['role_id']!=2) { ?>	
					<li class="layui-nav-item xinsu-nav-item-icon3 <?php if ($common_info['current'] == '3') { ?>layui-nav-itemed<?php } ?>">
						<a href="javascript:;">报表统计</a>
						<dl class="layui-nav-child">
							<dd <?php if ($common_info['current2'] == '1' && $common_info['current'] == '3') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/stock/bull">用户持仓</a></dd>
							<dd <?php if ($common_info['current2'] == '2' && $common_info['current'] == '3') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/stock/sell">用户平仓</a></dd>
							<dd <?php if ($common_info['current2'] == '3' && $common_info['current'] == '3') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/stock/trust">用户委托</a></dd>
							<dd <?php if ($common_info['current2'] == '4' && $common_info['current'] == '3') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/stock/hold">持仓统计</a></dd>
							<dd <?php if ($common_info['current2'] == '5' && $common_info['current'] == '3') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/stock/gain">盈亏排序</a></dd>
							<!-- <dd <?php if ($common_info['current2'] == '6' && $common_info['current'] == '3') { ?>class="layui-this"<?php } ?>><a href="javascript:;">涨跌停平仓手动</a></dd> -->
						</dl>
					</li>
					<li class="layui-nav-item xinsu-nav-item-icon4 <?php if ($common_info['current'] == '4') { ?>layui-nav-itemed<?php } ?>">
						<a href="javascript:;">款项相关</a>
						<dl class="layui-nav-child">
							<dd <?php if ($common_info['current2'] == '1' && $common_info['current'] == '4') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/userbill/charge">手动入款</a></dd>
							<dd <?php if ($common_info['current2'] == '2' && $common_info['current'] == '4') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/userbill/index">资金明细</a></dd>
							<dd <?php if ($common_info['current2'] == '3' && $common_info['current'] == '4') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/userbill/logs">用户账单</a></dd>
							<dd <?php if ($common_info['current2'] == '4' && $common_info['current'] == '4') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/atm">提款管理</a></dd>
							<dd <?php if ($common_info['current2'] == '5' && $common_info['current'] == '4') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/userbill/charge_log">充值管理</a></dd>
						</dl>
					</li>
					<li class="layui-nav-item xinsu-nav-item-icon5 <?php if ($common_info['current'] == '5') { ?>layui-nav-itemed<?php } ?>">
						<a href="javascript:;">其他功能</a>
						<dl class="layui-nav-child">
							<dd <?php if ($common_info['current2'] == '1' && $common_info['current'] == '5') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/news/index">新闻公告 丨 新增</a></dd>
							<dd <?php if ($common_info['current2'] == '2' && $common_info['current'] == '5') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/holiday">休市管理 丨 新增</a></dd>
							<dd <?php if ($common_info['current2'] == '3' && $common_info['current'] == '5') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/stockcode">股票管理 丨 新增</a></dd>
							<dd <?php if ($common_info['current2'] == '4' && $common_info['current'] == '5') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/stockcode/drxd">除权管理</a></dd>
							<dd <?php if ($common_info['current2'] == '5' && $common_info['current'] == '5') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/stockcode/check">检查新股</a></dd>
							<dd <?php if ($common_info['current2'] == '6' && $common_info['current'] == '5') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/message/mail">站内信</a></dd>
							<dd <?php if ($common_info['current2'] == '7' && $common_info['current'] == '5') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/message/money">提款信</a></dd>
							<dd <?php if ($common_info['current2'] == '8' && $common_info['current'] == '5') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/sms">短信管理</a></dd>
							<dd <?php if ($common_info['current2'] == '9' && $common_info['current'] == '5') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/system">系统设置</a></dd>
							<dd <?php if ($common_info['current2'] == '10' && $common_info['current'] == '5') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/config">股票板块</a></dd>
							<dd <?php if ($common_info['current2'] == '11' && $common_info['current'] == '5') { ?>class="layui-this"<?php } ?>><a href="/<?php echo $common_info['module']; ?>/news/rule">交易规则</a></dd>
							<dd><a href="javascript:logout();">注销登录</a></dd>
						</dl>
					</li>
					<?php } ?>
					<!-------End Admin Menus--------->
				</ul>
			</div>
		</div>
		<div class="xinsu-right">
			<div class="xinsu-right-content">
				<div class="xinsu-data-content">
					<div class="xinsu-title">
						<span class="layui-breadcrumb">
							<a><cite>当前位置</cite></a>
							<a><cite>保证金率</cite></a>
						</span>
					</div>
					<form class="layui-form xinsu-form" action="" method="get">
						<div class="layui-form-item">
						    <div class="layui-inline">
						      	<label class="layui-form-label xinsu-form-label">代理商</label>
						      	<div class="layui-input-inline xinsu-input-inline">
							        <select name="aid">
										<option value="0">全部</option>
										<?php foreach ($agent as $val) { ?>
										<option value="<?php echo $val['id']; ?>" <?php if ($aid == $val['id']) { ?>selected<?php } ?>><?php echo $val['username']; ?></option>
										<?php } ?>
									</select>
						        </div>
						    </div>
						    <div class="layui-inline">
						      	<label class="layui-form-label xinsu-form-label">账号类型</label>
						      	<div class="layui-input-inline xinsu-input-inline">
							        <select name="demo_account">
										<option value="2">全部</option>
										<option value="0" <?php if ($demo_account == 0) { ?>selected<?php } ?>>正式</option>
										<option value="1" <?php if ($demo_account == 1) { ?>selected<?php } ?>>试玩</option>
									</select>
						        </div>
						    </div>
						    <div class="layui-inline">
						    	<label class="layui-form-label xinsu-form-label">搜索条件</label>
								<div class="layui-input-block xinsu-input-block2">
								    <input type="text" name="username" value="<?php if ($username != '0') {  echo urldecode($username);  } ?>" class="layui-input" placeholder="帐号 / 真实姓名"/>
								</div>
						    </div>
						   <button class="layui-btn xinsu-btn">查询</button>
							<span>记录总数：共 <?php echo $total; ?> 条</span>
						</div>
					</form>
					<div class="layui-form xinsu-form">
						<table class="layui-table">
							<thead>
								<tr>
									<th>ID</th>
									<th>代理商</th>
									<th>员工</th>
									<th>帐号</th>
									<th>姓名</th>
									<th>资金余额</th>
									<th>可用额度</th>
									<th>保证金率</th>
									<th>类型</th>
									<th>状态</th>
									<th>开户日期</th>
									<th>最后登录</th>
									<th>最后登录IP</th>
									<th>操作</th>
								</tr> 
							</thead>
							<tbody>
								<?php if (empty($list) == false) { ?>
								<?php foreach ($list as $val) { ?>
								<tr>
									<td><?php echo $val['id']; ?></td>
									<td><?php echo $val['agent_name']; ?></td>
									<td><?php echo $val['staff_name']; ?></td>
									<td><a class="xinsu-fontcolor-blue xinsu-user" href="javascript:;" data="<?php echo $val['id']; ?>"><?php echo $val['username']; ?></a></td>
									<td><?php echo $val['realname']; ?></td>
									<td><?php echo $val['finance']; ?></td>
									<td><?php echo $val['amount']; ?></td>
									<td <?php if ($val['ratio'] < 50) { ?>class="xinsu-fontcolor-red"<?php } ?>><?php echo $val['ratio']; ?>%</td>
									<?php if ($val['demo_account'] == 0) { ?>
									<td class="xinsu-fontcolor-green">正式</td>
									<?php } else { ?>
									<td class="xinsu-fontcolor-red">试玩</td>
									<?php } ?>
									<?php if ($val['is_online'] == 0 || time() - $val['last_login'] >= 3600) { ?>
									<td>离线</td>
									<?php } else { ?>
									<td class="xinsu-fontcolor-red">在线</td>
									<?php } ?>
									<td><?php echo date("Y-m-d H:i:s", $val['reg_date']); ?></td>
									<td><?php echo date("Y-m-d H:i:s", $val['last_login']); ?></td>
									<td><?php echo long2ip($val['ip']); ?></td>
									<td>
										<a class="xinsu-send-sms xinsu-fontcolor-blue" data-id="<?php echo $val['id']; ?>" href="javascript:;">发信</a>
										<a id="xinsu-locked-<?php echo $val['id']; ?>" class="<?php if ($val['is_locked'] == 0) { ?>xinsu-fontcolor-blue<?php } else { ?>xinsu-fontcolor-red<?php } ?> xinsu-change" href="javascript:;" data="<?php echo $val['id']; ?>"  data-uri="/user/change/locked/<?php echo $val['id']; ?>"><?php if ($val['is_locked'] == 1) { ?>解锁<?php } else { ?>锁定<?php } ?></a>	
										<a id="xinsu-disable-<?php echo $val['id']; ?>" class="<?php if ($val['is_disable'] == 0) { ?>xinsu-fontcolor-blue<?php } else { ?>xinsu-fontcolor-red<?php } ?>  xinsu-change" href="javascript:;" data="<?php echo $val['id']; ?>"  data-uri="/user/change/disable/<?php echo $val['id']; ?>"><?php if ($val['is_disable'] == 1) { ?>启用<?php } else { ?>禁用<?php } ?></a>
										<a id="xinsu-stop-<?php echo $val['id']; ?>" class="<?php if ($val['is_stop'] == 0) { ?>xinsu-fontcolor-blue<?php } else { ?>xinsu-fontcolor-red<?php } ?>  xinsu-change" href="javascript:;" data="<?php echo $val['id']; ?>"  data-uri="/user/change/stop/<?php echo $val['id']; ?>"><?php if ($val['is_stop'] == 1) { ?>开仓<?php } else { ?>停仓<?php } ?></a>
										<a class="xinsu-fontcolor-blue xinsu-amend xinsu-edit" href="javascript:;" data="<?php echo $val['id']; ?>">修改</a>
										<?php if ($val['id'] != 1 && $val['id'] != $_SESSION['admin']['id'] && $_SESSION['admin']['role_id'] == 0) { ?>
										<?php } ?>
									</td>
								</tr>
								<?php } ?>
								<?php } else { ?>
								<tr>
									<td colspan="11">暂无数据</td>
								</tr>
								<?php } ?>
							</tbody>
						</table>
					</div>
					<div class="xinsu-page">
						<div class="xinsu-show">
							<?php echo $page; ?>
						</div>
						<div class="xinsu-clear"></div>
					</div>
				</div>
			</div>
		</div>
		<script src="<?php echo STATIC_SERVER; ?>/layui/layui.all.js"></script>
		<script>
			
			$(function (){
				//根据代理获取员工
				var form  = layui.form();
				form.on('select(aid)', function(data){
					var url = "/agent/ajax_get_staff";
					var aid = data.value;
					if (aid == "0") {
						$("select[name='sid']").html('<option value="0">不限制</option>');
						form.render('select');
					} else {
						http_request_post(url, {aid:aid}, function(result){
							$("select[name='sid']").html("");
							html = '<option value="0">全部员工</option>';
							if (result.status == 1) {
								var res = eval(result.data);
								$.each(res, function(key, val){
									html += '<option value="'+val.id+'">'+val.username+'</option>';
								})
							}
							$("select[name='sid']").html(html);
							form.render('select');
						});
					}
				});
				
				//更改导航选中状态
				$(".layui-nav-item").click(function (){
						$(".layui-nav-item").removeClass("layui-nav-itemed");
						if (! $(this).hasClass("layui-nav-itemed")) {
							$(this).addClass("layui-nav-itemed");
						} else {
							$(this).removeClass("layui-nav-itemed");
							$(this).find("dd").removeClass("layui-this");
						}
					})
					
				//获取服务器时间
				//get_system_time();
				//get_system_info();
			})
			var system_info = system_time = system_holiday = 0;
			var token = "<?php echo $token; ?>";
			//获取系统时间
			var time = <?php echo round(microtime(true) * 1000); ?>;
			var n = t = 0; 
			function get_system_time() {
				//防止用户退出继续请求
				if (system_time >= 0) {
					t = new Date(time);
					n = (t.getHours() < 10 ? "0" :"") + t.getHours() + ":" + (t.getMinutes() < 10 ? "0" :"") + t.getMinutes() + ":" + (t.getSeconds() < 10 ? "0" :"") + t.getSeconds();
					$("#xinsu-system-time").html(n);
					time += 1000;
					system_time = setTimeout("get_system_time();", 1000);
				}
			}
			
			//获取系统时间
			function get_system_info() {
				//防止用户退出继续请求
				if (system_info >= 0) {
					var url = "/index/get_system_info";
					http_request_post(url, "", function(res) {
						var result = res.data;
						$("#xinsu-message").html(result.message);
						if (result.holiday == "休市") {
							system_holiday = 1;
						} else {
							system_holiday = 0;
						}
						system_info = setTimeout("get_system_info();", 1000);
					});
				}
			}

			//清除系统缓存
			function clear_system_cache() {
				layer.confirm('您确定要更新缓存？', {icon: 3}, function () {
					var url = "/index/clear_system_cache";
					layer.closeAll();
					http_request_post(url, null, function(res) {
						layer.msg(res.msg, {icon: 1,time: 800});
					});
				});
			}
					
			//退出登录
			function logout() {
				layer.confirm('您确定要退出？', {icon: 3}, function () {
					stock = system_info = -1
					var url = "/index/logout";
					layer.closeAll();
					http_request_post(url, null, function(res) {
						layer.msg(res.msg, {icon: 1, time: 800}, function () {
							//跳转到登录页面
							location.href = "/<?php echo $common_info['module']; ?>/index/login";
						});
					});
				});
			}
					
			//新增表单
			$(".xinsu-add a").click(function (){
				location.href = "/<?php echo $common_info['module']; ?>/<?php echo $common_info['controller']; ?>/add";
			})
					
			//修改表单
			$(".xinsu-edit").click(function (){
				var id = $(this).attr("data");
				location.href = "/<?php echo $common_info['module']; ?>/<?php echo $common_info['controller']; ?>/edit/" + id;
			})
					
			//删除数据
			$(".xinsu-delete").click(function (){
				var id = $(this).attr("data");
				var url = "/<?php echo $common_info['controller']; ?>/delete/" + id;
				layer.confirm('您确定要删除记录？', {icon: 3}, function () {
					layer.closeAll();
					http_request_post(url, {}, function (result) {
						if (result.status == 1) {
							layer.msg(result.msg, {icon: 1, time: 800}, function () {
									//跳转到登录页面
									location.reload();
								});
						} else {
							layer.msg(result.msg);
						}
					});
				});
			})
				
			//更新数据
			$(".xinsu-change").click(function (){
				var url = $(this).attr("data-uri");
				http_request_post(url, {}, function (result) {
					if (result.status == 1) {
						layer.msg(result.msg, {icon: 1, time: 800}, function () {
							var res = eval(result.data);
							var id = res["id"];
							var field = res["field"];
							var is_field = res[field];
							if (is_field == 1) {
								if (field == "locked") {
									var msg = "解锁";
								} else if (field == "disable") {
									var msg = "启用";
								} else {
									var msg = "开仓";
								}
								$("#xinsu-"+field+"-" + id).html(msg);
								$("#xinsu-"+field+"-" + id).removeClass("xinsu-fontcolor-blue");
								$("#xinsu-"+field+"-" + id).addClass("xinsu-fontcolor-red");
							} else {
								if (field == "locked") {
									var msg = "锁定";
								} else if (field == "disable") {
									var msg = "禁用";
								} else {
									var msg = "停仓";
								}
								$("#xinsu-"+field+"-" + id).html(msg);
								$("#xinsu-"+field+"-" + id).removeClass("xinsu-fontcolor-red");
								$("#xinsu-"+field+"-" + id).addClass("xinsu-fontcolor-blue");
							}
						});
					} else {
						layer.msg(result.msg);
					}
				});
			})
					
			//股票K线图弹出框
			$('.xinsu-stock-figure').click(function(){
				var data = $(this).attr("data");
				layer.open({ 
					type: 1,
					title: '股票代码：' + data +' K线图',
					area: ['550px', '400px'],
					shadeClose: true,
					content: '<div class="layui-tab layui-tab-card" style="margin:0; height:99%;"><ul class="layui-tab-title"><li class="layui-this">分时线</li><li>日K线</li><li>周K线</li><li>周K线</li></ul><div class="layui-tab-content" style="height: 100px;"><div class="layui-tab-item layui-show"><img style="width:100%" src="http://image2.sinajs.cn/newchart/min/n/'+data+'.gif"></div><div class="layui-tab-item"><img  style="width:100%" src="http://image2.sinajs.cn/newchart/daily/n/'+data+'.gif"></div><div class="layui-tab-item"><img  style="width:100%" src ="http://image2.sinajs.cn/newchart/weekly/n/'+data+'.gif"></div><div class="layui-tab-item"><img  style="width:100%" src ="http://image2.sinajs.cn/newchart/monthly/n/'+data+'.gif"></div></div></div>'
				});
			});
					
			//用户信息弹出框
			$('.xinsu-user').click(function(){
				var id = $(this).attr("data");
				http_request_post("/user/get_user_info", {id : id}, function (result) {
					if (result.status == 1) {
						var res = eval(result.data);
						if (res.demo_account == 0) {
							var demo_account = "正式";
						} else {
							var demo_account = "试玩";
						}
						layer.open({ 
							type: 1,
							title: '会员 ' + id + ":" + res.username + ' 详细信息',
							area: ['600px', '380px'],
							shadeClose: true, //点击遮罩关闭
							content: '<div class="layui-form xinsu-form"><table class="layui-table xinsu-table"><tbody><tr><td>会员账号</td><td style="text-align: left">'+res.username+'</td><td>姓名</td><td style="text-align: left">'+res.realname+'</td></tr><tr><td>账号类型</td><td style="text-align: left">'+demo_account+'</td><td>手机</td><td style="text-align: left">'+res.mobile+'</td></tr><tr><td>保证金</td><td style="text-align: left">￥'+res.finance+'</td><td>可用额度</td><td style="text-align: left">￥'+res.amount+'</td></tr><tr><td>持仓金额</td><td style="text-align: left">￥'+res.bull_money+'</td><td>总资产</td><td style="text-align: left">￥'+res.total_assets+'</td></tr><tr><td>浮动盈亏</td><td style="text-align: left">￥'+res.total_gain+'</td><td>净资产</td><td style="text-align: left">￥'+res.net_assets+'</td></tr><tr><td>保证金率</td><td style="text-align: left">'+res.ratio+'%</td><td>可提现金额</td><td style="text-align: left">￥'+res.cash+'</td></tr><tr><td>注册时间</td><td style="text-align: left">'+res.reg_date+'</td><td>最后登录时间</td><td style="text-align: left">'+res.last_login+'</td></tr><tr><td>上级代理</td><td style="text-align: left">'+res.agent_name+'</td><td>所属员工</td><td style="text-align: left">'+res.staff_name+'</td></tr></tbody></table></div>'
						});
					}
				})
			});
			$('.xinsu-content').click(function(){
				var url = $(this).attr("data-uri");
				var title = $(this).attr("data-title");
				layer.open({
						type: 2,
						title: title,
						shadeClose: true,
						area: ['550px', '250px'],
						skin: 'layui-layer-rim', //加上边框
						content:[ url ,'auto' ] //iframe的url
					});
			});		
			//发送短信或站内信
			$(".xinsu-send-sms").click(function(){
				var id = $(this).attr('data-id');
				var url = "/sms/ajax_get_user_info";
				
				http_request_post(url, {id:id}, function(result){
					if(result.status==1){
						var username = result.data.username,realname = result.data.realname,phone = result.data.mobile,sex = result.data.sex;
						layer.open({ 
							type: 1,
							title: '会员'+id+' 的详细信息',
							area: ['550px', '400px'],
							btn:['确定', '取消'],
							shadeClose: true, //点击遮罩关闭
							content: '<div style="padding:10px 40px 0 40px; line-height:36px; font-size:14px;">'+
							'<form class="xinsu-form">'+
							'<table class="layui-table xinsu-table">'+
							'<tbody>'+
							'<tr><td nowrap="nowrap">发送用户：</td><td style="text-align: left;">'+username+'('+realname+') </td></tr>'+
							'<tr><td nowrap="nowrap">手机号码：</td><td style="text-align: left;">'+phone+'</td></tr>'+
							'<tr><td nowrap="nowrap">模板：</td><td align="left" nowrap="nowrap"><div align="left">'+
							'<input type="radio" name="msg_type" value="1" checked onclick="javascript:$(\'#content\').val(\'尊敬的'+realname+sex+'，您好！账号'+username+'已为您激活,初始密码：abc123，网址<?php echo $_SERVER['HTTP_HOST']; ?>,请点击会员登录进入，请收到账号后及时登录交易平台修改初始密码，若需相关咨询，请拔打客服热线0371-53690183，恭祝您生活愉快\');$(\'#xinsu-sms-title\').hide();">账户&nbsp;&nbsp;'+
							'<input type="radio" name="msg_type"  value="2"  onclick="javascript:$(\'#content\').val(\'尊敬的'+realname+sex+'，您好！账号'+username+'浮动亏损过大，请您注意风险，随时关注账户变化情况。\');$(\'#xinsu-sms-title\').hide();">风险&nbsp;&nbsp;'+
							'<input type="radio" name="msg_type" value="3" onclick="javascript:$(\'#content\').val(\'尊敬的'+realname+sex+'，您好！账号'+username+'保证金率低于50%，请于当天20:00点之前补足100%，如未能在当天补足，则系统将于次个交易日开市后将超出部分按比例以市价平仓。\');$(\'#xinsu-sms-title\').hide();">追加&nbsp;&nbsp;'+
							'<input type="radio" name="msg_type" value="4" onclick="javascript:$(\'#content\').val(\'尊敬的'+realname+sex+'，您好！账号'+username+'中(代码)明日除权除息，请予今日下午收盘前平仓该订单，若您未自行平仓，则系统会强制平仓，谢谢合作。\');$(\'#xinsu-sms-title\').hide();">除权&nbsp;&nbsp;'+
							'<input type="radio" name="msg_type" value="5" onclick="javascript:$(\'#content\').val(\'尊敬的'+realname+sex+'，您好！账号'+username+'有定单留仓天数到达规定天数10天，建议您随时关注，选择合适价位平仓，否则系统会在收盘前平仓您留仓10天的定单，若需相关咨询，请拔打客服热线0371-53690183，恭祝您生活愉快。\');$(\'#xinsu-sms-title\').hide();">留仓&nbsp;&nbsp;'+
							'<input type="radio" name="msg_type" value="6" onclick="javascript:$(\'#content\').val(\'自己编写手机短信\');$(\'#xinsu-sms-title\').hide();">自编&nbsp;&nbsp;'+
							'<input type="radio" name="msg_type" value="7" onclick="javascript:$(\'#content\').val(\'自己编写站内信\');$(\'#xinsu-sms-title\').show();">站内'+
							'</div></td></tr><tr id="xinsu-sms-title" style="display:none;"><td>标题：</td><td><div align="left"><input type="text" name="title" id="title" size=45></div></td></tr>'+
							'<tr><td nowrap="nowrap">内容：</td><td><div align="left"><textarea name="content" id="content" cols="50" rows="6">尊敬的'+realname+sex+'，您好！账号'+username+'已为您激活,初始密码：abc123，网址<?php echo $_SERVER['HTTP_HOST']; ?>,请点击会员登录进入，请收到账号后及时登录交易平台修改初始密码，若需相关咨询，请拔打客服热线0371-53690183，恭祝您生活愉快。</textarea></div></td></tr>'+
							'</tbody></table></form></div>',
							yes:function(index, layers){
								var title = $("#title").val();
								var type = $("input[name='msg_type']:checked").val();
								var content = $("#content").val();
								url = "/sms/send";
								layer.closeAll();
								http_request_post(url, {id:id,phone:phone, title:title, type:type,content:content}, function(result){
									layer.msg(result.msg, {icon:1, time:800}, function(){});
								});
							}
						});		
					} else {
						layer.msg(result.msg);
					}
				});
			});
				
			//提交表单
            var sub = 0;
			$("form").submit(function () {
				//判断提交方式：get-搜索专用，post-保存专用
				var method = $(this).attr("method");
				if (method == "post") {
					//保存专用
					var data = $(this).serialize();
					data += "&token="+token;
					layer.confirm('您确定要执行？', {icon: 3}, function () {
                        sub += 1;
						layer.closeAll();
                        if (sub == 1) {
                            http_request_post("", data, function (result) {
                                layer.msg(result.msg, {icon:1, time:800}, function (){
                                    if (result.data != "") {
                                        location.href = "/<?php echo $common_info['module']; ?>" + result.data;
                                    } else {
                                        location.reload();
                                    }
                                });
                            });
                        }
					});
					return false;
				} else {
					//搜索专用
					var data = $(this).serializeArray();
					var	url = "/<?php echo $common_info['module']; ?>/<?php echo $common_info['controller']; ?>/<?php echo $common_info['action']; ?>";
					$.each(data, function(key, val) {
							if (val.value == "") {
								url += "/0";
							} else {
								url += "/" + val.value;
							}
						});
					location.href = url;
					return false;
				}
			})
					
					
			//通用post请求
			function http_request_post(url, data, callback) {
				if (url != "") {
					url = "/<?php echo $common_info['module']; ?>" + url;
				}	
				$.ajax({
					type : 'post',  
					url : url,
					dataType : 'json',
					data : data,
					success : function(repones) {
						if (repones.status == 1) {
							if (typeof callback === "function") {
								callback(repones);
								return false;
							} else {
								layer.msg('请求加载数据失败，请重新加载');
							}
						} else if (repones.status == 2) {
							layer.msg(repones.msg, {icon:0, time:800}, function (){
								location.href = "/<?php echo $common_info['module']; ?>/index/login";
							});
						}  else if (repones.status == 0) {
							token = repones.token;
							layer.msg(repones.msg);
							return false;
						} else {
							layer.msg(repones.msg);
							return false;
						}
					},
					error : function () {  
						layer.msg('加载数据失败，请重新加载');
						return false;
					}
				});
				return false;
			}
		</script>
	</body>
</html>
